from django.http import JsonResponse
from django.urls import path

from .views import (person_center, login, register, logout, send_verify_code, update_profile, cancel_participation,
                    toggle_follow, get_follow_data, get_user_info, upload_avatar, get_section_data,
                    # 新增admin_dashboard
                    toggle_block, clear_notifications, admin_index, admin_dashboard, ban_user, unban_user, delete_user,
                    admin_redirect, approve_activity, reject_activity, delete_activity, add_category,
                    edit_category, delete_category, points_mall, points_history, points_rules,
                    exchange_product, my_exchanges,
                    clear_chat_history, invite_to_group, get_group_info,
                    leave_group, update_group_info, talking, create_chat_group, search_users, section_data,
                    get_following_list, get_followers_list, daily_signin, debug_exchanges,
                    admin_points_history, cancel_activity, get_joined_activities, get_my_activities,
                    send_chat_message, get_online_users, get_chat_history, qq_login, qq_callback,
                    admin_activity_detail, get_private_chat_history, get_group_chat_history,
                    # 添加积分管理相关视图
                    points_management, points_exchanges, add_points_product, update_points_product,
                    delete_points_product, update_exchange_status)

urlpatterns = [
    # 认证相关
    path('login/', login, name='login'),
    path('register/', register, name='register'),
    path('logout/', logout, name='logout'),

    # 个人资料管理
    path('update_profile/', update_profile, name='update_profile'),
    path('upload_avatar/', upload_avatar, name='upload_avatar'),
    path('send_verify_code/', send_verify_code, name='send_verify_code'),

    # 个人中心
    path('person_center/', person_center, name='person_center'),
    path('cancel_participation/<int:activity_id>/', cancel_participation, name='cancel_participation'),
    path('section_data/<str:section>/', section_data, name='section_data'),
    path('get_user_info/', get_user_info, name='get_user_info'),
    path('toggle_follow/', toggle_follow, name='toggle_follow'),

    path('my_activities/', get_my_activities, name='my_activities'),
    path('joined_activities/', get_joined_activities, name='joined_activities'),
    path('cancel_activity/<int:activity_id>/', cancel_activity, name='cancel_activity'),
    path('delete_activity/<int:activity_id>/', delete_activity, name='delete_activity'),

    # 聊天相关路由
    path('talking/', talking, name='talking'),
    path('section_data/<str:section>/', section_data, name='section_data'),
    path('api/get_chat_history/', get_chat_history, name='get_chat_history'),
    path('api/get_online_users/', get_online_users, name='get_online_users'),
    path('create_chat_group/', create_chat_group, name='create_chat_group'),
    path('get_group_info/', get_group_info, name='get_group_info'),
    path('leave_group/', leave_group, name='leave_group'),
    path('clear_chat_history/', clear_chat_history, name='clear_chat_history'),
    path('send_chat_message/', send_chat_message, name='send_chat_message'),
    path('search_users/', search_users, name='search_users'),

    # 社交功能
    path('toggle_block/', toggle_block, name='toggle_block'),
    path('clear_notifications/', clear_notifications, name='clear_notifications'),
    path('get_follow_data/', get_follow_data, name='get_follow_data'),
    path('get_private_chat_history/', get_private_chat_history, name='get_private_chat_history'),
    path('get_group_chat_history/', get_group_chat_history, name='get_group_chat_history'),

    # 管理员功能
    path('admin_index/', admin_index, name='admin_index'),
    # 新增admin_dashboard/
    path('admin_dashboard/', admin_dashboard, name='admin_dashboard'),
    path('admin/ban_user/<int:user_id>/', ban_user, name='ban_user'),
    path('admin/unban_user/<int:user_id>/', unban_user, name='unban_user'),
    path('admin/delete_user/<int:user_id>/', delete_user, name='delete_user'),
    path('go-admin/', admin_redirect, name='admin_redirect'),

    # 活动管理
    path('admin/approve_activity/<int:activity_id>/', approve_activity, name='approve_activity'),
    path('admin/reject_activity/<int:activity_id>/', reject_activity, name='reject_activity'),

    # 分类管理
    path('admin/add_category/', add_category, name='add_category'),
    path('admin/edit_category/<int:category_id>/', edit_category, name='edit_category'),
    path('admin/delete_category/<int:category_id>/', delete_category, name='delete_category'),

    # 积分商城相关URL
    path('points/mall/', points_mall, name='points_mall'),
    path('points/history/', points_history, name='points_history'),
    path('points/rules/', points_rules, name='points_rules'),
    path('points/exchange/<int:product_id>/', exchange_product, name='exchange_product'),
    path('points/my_exchanges/', my_exchanges, name='my_exchanges'),
    path('points/daily_signin/', daily_signin, name='daily_signin'),
    path('debug_exchanges/', debug_exchanges, name='debug_exchanges'),

    # 积分管理相关URL
    path('admin/points/', points_management, name='points_management'),
    path('admin/points/history/', admin_points_history, name='admin_points_history'),
    path('admin/points/exchanges/', points_exchanges, name='points_exchanges'),
    path('admin/points/product/add/', add_points_product, name='add_points_product'),
    path('admin/points/product/<int:product_id>/update/', update_points_product, name='update_points_product'),
    path('admin/points/product/<int:product_id>/delete/', delete_points_product, name='delete_points_product'),
    path('admin/points/exchange/<int:exchange_id>/update_status/', update_exchange_status,
         name='update_exchange_status'),

    # 第三方登录
    path('qq_login/', qq_login, name='qq_login'),
    path('qq_callback/', qq_callback, name='qq_callback'),

    # 其他
    path('admin_activity_detail/<int:activity_id>/', admin_activity_detail, name='admin_activity_detail'),
]


def section_data(request, section):
    """根据section参数返回不同的数据"""
    if section == 'following':
        return get_following_list(request)
    elif section == 'followers':
        return get_followers_list(request)
    elif section == 'my-activities':
        # 返回用户发布的活动
        pass
    elif section == 'joined-activities':
        # 返回用户参与的活动
        pass
    else:
        return JsonResponse({'success': False, 'message': '未知的section'})